import numpy as np
from sklearn.metrics.pairwise import rbf_kernel
import yfinance as yf
import datetime as date
import math

fields = "date,open,close,volume"

start = date.datetime(2023, 2, 13)
end = date.datetime(2023, 2, 17)
data = yf.download('601318.ss', start, end)

# 求各参数的平均值和方差
means = np.mean(data, axis=0)
variance = np.var(data, axis=0)
print('各维度均值：\n', means)
print('各维度方差：\n', variance)

# Pearson(皮尔逊)相关系数
correleations = np.round(np.corrcoef(data, rowvar=False), 2)
print('皮尔逊系数：\n', correleations)

# 计算高斯核
X = data.iloc[:, :-1].values
sigma = 0.5  # σ
K = np.round(rbf_kernel(X, gamma=1 / (2 * sigma ** 2)), 2)
print(K)
with open('data.csv', 'w') as f:
    f.write(str(K))

